//
//  MyChartView.swift
//  APPTestSwift
//
//  Created by hiking on 2020/2/28.
//  Copyright © 2020 hiking. All rights reserved.
//

import UIKit

class MyChartView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame:frame)
        self.backgroundColor = .systemBlue
    }
    
   
    override func layoutSubviews() {
        super.layoutSubviews()
    }
    
    override func draw(_ rect: CGRect) {
        super.draw(rect)
        //获取绘图上下文
        guard let context:CGContext = UIGraphicsGetCurrentContext() else {
            return
        }
        context.setLineWidth(1)
        context.setStrokeColor(UIColor.yellow.cgColor)
        context.beginPath()
        context.move(to: CGPoint.init(x: 10, y: 10))
        context.addLine(to: CGPoint.init(x: self.frame.width-10, y: 10))
        context.strokePath()
    
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        for touch :AnyObject in touches {
            let t : UITouch  = touch as! UITouch
            //在屏幕上连续拍击两次，背景变为灰色
            if (t.tapCount == 2) {
                self.backgroundColor = UIColor.gray
            }else if(t.tapCount == 1){
                self.backgroundColor = UIColor.brown
            }
            print("begin")
        }
    }
    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        for touch : AnyObject in touches {
            let t : UITouch = touch as! UITouch
            print(t.location(in:self))
        }

    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
